package com.leyou.controller;

import com.leyou.service.FileService;
import com.leyou.service.PageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
@RequestMapping("item")
public class PageController {
    @Autowired
    private PageService pageService;

    @Autowired
    private FileService fileService;

    @GetMapping("{id}.html")
    public String toItemPage(Model model, @PathVariable("id") Long id){
        //把查询到的值存入thymeleaf的context中
        model.addAllAttributes(pageService.loadModel(id));
        if(!this.fileService.exists(id)){
//            this.fileService.syncCreateHtml(id);
        }
        //跳入对应页面
        return "item";
    }
}
